package com.dnjn.happiness.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.Outlet;
import com.dnjn.happiness.biz.domain.vo.OutletVO;
import com.dnjn.happiness.biz.service.IOutletService;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 1780055116377604098Controller
 *
 * @author happiness
 * @date 2024-03-13
 */
@Tag(name = "biz outlet 解忧馆", description = "解忧馆")
@RestController
@RequestMapping("/outlet")
public class OutletController extends BaseController {
    @Autowired
    private IOutletService outletService;

    /**
     * 查询解忧馆列表
     */
    //@RequiresPermissions("@ss.hasPermi('biz:outlet:list')")
    @PostMapping("/list")
    @Log(title = "biz", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody OutletVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        Outlet outlet = new Outlet();
        BeanUtils.copyPropsIgnoreNull(vo, outlet);
        Page page = Page.of(current, size);
        outlet.setUserId(SecurityUtils.getUserId());
        Page<OutletVO> list = outletService.getPage(page, outlet);
        outletService.getOutletReplyList(list.getRecords());
        return success(list);
    }

    /**
     * 获取解忧馆详细信息
     */
    //@RequiresPermissions("@ss.hasPermi('biz:outlet:query')")
    @GetMapping(value = "/{outletId}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("outletId") Long outletId) {
        return success(outletService.getById(outletId));
    }

    /**
     * 新增解忧馆
     */
    @Log(title = "解忧馆", businessType = BusinessType.INSERT)
//    @RequiresPermissions("@ss.hasPermi('biz:outlet:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OutletVO vo) {
        Outlet outlet = new Outlet();
        BeanUtils.copyPropsIgnoreNull(vo, outlet);
        outletService.setOutletField(outlet);
        return toAjax(outletService.save(outlet));
    }


    /**
     * 修改解忧馆
     */
    @Log(title = "解忧馆", businessType = BusinessType.UPDATE)
    //@RequiresPermissions("@ss.hasPermi('biz:outlet:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OutletVO vo) {
        Outlet outlet = new Outlet();
        BeanUtils.copyPropsIgnoreNull(vo, outlet);
        return toAjax(outletService.updateById(outlet));
    }

    /**
     * 删除解忧馆
     */
    @Log(title = "解忧馆", businessType = BusinessType.DELETE)
    //@RequiresPermissions("@ss.hasPermi('biz:outlet:remove')")
    @DeleteMapping("/{outletIds}")
    public AjaxResult remove(@PathVariable Long[] outletIds) {
        return toAjax(outletService.removeBatchByIds(Arrays.asList(outletIds)));
    }

    /**
     * 点击催
     */
    @GetMapping(value = "urge/{outletId}")
    public AjaxResult urge(@PathVariable("outletId") Long outletId) {
        Assert.notNull(outletId, "outletId不能为空");
        outletService.urge(outletId);
        return success();
    }


}
